<template>
  <view class="outBox">
    <u-navbar leftText="电子账户余额" leftIconColor="#fff" :autoBack="true" bgColor="rgba(0, 0, 0, 0.6)">
      <view class="left-slot" slot="left">
        <u-icon name="arrow-left" color="#fff"></u-icon>
        <text>{{ '电子账户余额' }}</text>
      </view>
    </u-navbar>

    <VideoBox>
      <template #content>
        <view class="content">
          <view class="cardInfo">
            <image class="cardBg" :src="getImgUrlLocal('/mine/cardInfo.png')" mode="widthFix"></image>
            <view class="title">电子账户余额<image @click="showInfoBox" class="wenhao" style="width: 32rpx;" src="/static/reservation/img2.png" mode="widthFix" /></view>
            <view class="price">¥{{ dataInfo.accountBalancePrice || 0 }}</view>
          </view>
          <view class="items">
            <view class="tip">电子账户记录</view>
            <view class="empty" v-if="!dataInfo.accountDetailList || dataInfo.accountDetailList.length == 0">
              <text>暂无记录</text>
            </view>
            <view v-else>
              <view class="item" v-for="(item,index) in dataInfo.accountDetailList" :key="index"
                    @click="handleDetails(item)">
                <view class="left">
                  <view class="top">
                    <view class="tag" :class="item.type == '转出' ? 'tag2' : ''">
                      <text>{{ item.type }}</text>
                    </view>
                    <text class="name">{{ item.counterNo || '' }}</text>
                  </view>
                  <view class="bottom">
                    <text>操作时间：{{ item.operateTime }}</text>
                  </view>
                </view>
                <view class="right">
                  <view class="price">
                    <text>{{ item.type == '转入' ? '+' : '-' }}{{ item.accountDetailprice }}元</text>
                  </view>
                </view>
              </view>

            </view>
          </view>
        </view>
      </template>
    </VideoBox>
    <DiaBox ref="diaBox" @comfireFunc="comfireFunc" title="电子账户规则" :isClose="false"
            :show-cancel="false" :showBtns="true">
      <template slot="dia-cont">
        <view class="textBox">
		  <p>电子账户余额可消费任意商品（当月取消次数＞12次，电子账户余额清零；超过3个月未使用电子账户，电子账户余额清零）。</p>
        </view>
      </template>
    </DiaBox>
  </view>
</template>

<script>
import {
  getWXStatusHeight,
  getImgUrlLocal, getDateForYmd
} from '@/utils/index.js'

import {
  findAccountDetailForWx
} from "@/api/api.js"
import VideoBox from "@/components/VideoBox/index.vue";
import DiaBox from "@/components/diaBox/index.vue";

export default {
  components: {DiaBox, VideoBox},
  data() {
    return {
      videoUrl: this.$videoUrl,
      baseImgUrl2: '/static',
      seconds: 90,
      // 胶囊的宽度
      barWidth: 0,
      menuHeight: 0,
      dataInfo: {},
      isFirstEnter: {},
      timer: {},
      timer2: {},
    }
  },
  onLoad() {
    let obj = getWXStatusHeight()
    this.barWidth = obj.barWidth + 3
    this.menuHeight = obj.menuHeight
    this.getData()
	 const isFirstEnter = uni.getStorageSync('isFirstEnter2')
	 if (isFirstEnter) return
	 this.showInfoBox()
  },
  methods: {
    getImgUrlLocal,
    async getData() {
      const res = await findAccountDetailForWx()
      if (res.code == 200) {
        this.dataInfo = res.data
      }
    },
    comfireFunc() {
      if (this.isFirstEnter.flag == '是') {
        // 判断时间是否过去5秒
        if (Date.now() - this.timer < 5000) {
          this.$refs.diaBox.show = true
          uni.$u.toast('阅读5秒可关闭')
        } else {
          const date = getDateForYmd()
          this.isFirstEnter.flag = '否'
          this.isFirstEnter.date = date
          this.$refs.diaBox.show = false
          uni.setStorageSync('isFirstEnter2', this.isFirstEnter)
        }
      } else {
        this.$refs.diaBox.show = false
      }
    },
    showInfoBox() {
      const isFirstEnter = uni.getStorageSync('isFirstEnter2')

      this.$refs.diaBox.show = true
      // 记录当前时间
      this.timer = Date.now()
      this.isFirstEnter.flag = '是'
      const date = getDateForYmd()
      this.isFirstEnter.date = date

      // 开启定时器，刷新提示语 每一秒刷新一次 5秒后结束
      this.timer2 = setInterval(() => {
        // 剩余时间
        let time = 5 - Math.floor((Date.now() - this.timer) / 1000)
        if (time <= 0) {
          clearInterval(this.timer2)
        }
      }, 1000)
    },
  }
}
</script>

<style lang="scss" scoped>
.cardInfo {
  width: 100%;
  height: 300rpx;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;

  .cardBg {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
  }
  
  .title {
    color: #86909C;
    font-size: 28rpx;
    margin-bottom: 52rpx;
	display: flex;
	align-items: center;
	image{
		margin-left: 20rpx;
	}
  }

  .price {
    font-weight: normal;
    font-size: 40rpx;
    color: #FFFFFF;
    line-height: 40rpx;
    text-align: left;
    font-style: normal;
    white-space: nowrap;
  }
}

.empty {
  flex: 1;
  color: #86909C;
  display: flex;
  align-items: center;
  justify-content: center;
}

.items {
  flex: 1;
  margin-top: 52rpx;
  background: rgba(0, 0, 0, 0.41);
  border-radius: 86rpx;
  border: 2rpx solid #262a3c;
  backdrop-filter: blur(7px);
  padding: 48rpx;
  min-height: 400rpx;
  margin-bottom: 50rpx;
  display: flex;
  flex-direction: column;

  .tip {
    font-weight: 400;
    font-size: 26rpx;
    color: #86909C;
    line-height: 28rpx;
    text-align: left;
    font-style: normal;
  }

  .item {
    border-bottom: 2rpx solid #1d231f;
  }

  .item {
    display: flex;
    justify-content: space-between;
    padding: 40rpx 0;
    margin-bottom: 18rpx;
    box-sizing: border-box;
    background-size: 100% 100%;

    .tag {
      width: 76rpx;
      height: 40rpx;
      background: #0FC6C2;
      border-radius: 14rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 16rpx;

      text {
        font-weight: 400;
        font-size: 25rpx;
        color: #FFFFFF;
      }
    }

    .tag2 {
      background: #FF9A2E;
    }

    .right {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      .price {
        font-weight: 500;
        font-size: 36rpx;
        color: #FFFFFF;
        line-height: 36rpx;
        text-align: right;
        font-style: normal;
      }

      .top {
        margin-bottom: 34rpx;

        text {
          color: #E8EF89;
          font-size: 24rpx;
        }
      }

      .status {
        font-family: Microsoft YaHei, Microsoft YaHei;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 116rpx;
        height: 42rpx;
        background: #192A15;
        border-radius: 200rpx 200rpx 200rpx 200rpx;
        border: 2rpx solid #3ED060;

        text {
          font-weight: 400;
          font-size: 20rpx;
          color: #32F178;
        }
      }
    }

    .right2 {
      .top {
        text {
          font-weight: 500;
          font-size: 36rpx;
          color: #FFFFFF;
          line-height: 36rpx;
          text-align: right;
          font-style: normal;
        }
      }

      .status1 {
        border-color: #67E3FF;
        background: #153337;

        text {
          color: #67E3FF;
        }
      }

      .status2 {
        border-color: #414141;
        background: #282828;

        text {
          color: #414141;
        }
      }
    }

    .left {
      .top {
        display: flex;
        margin-bottom: 20rpx;

        .name {
          font-size: 32rpx;
          color: #FFFFFF;
        }

      }

      .bottom {
        font-size: 24rpx;
        color: #86909C;
        line-height: 28rpx;
        text-align: left;
        font-style: normal;

        .one {
          display: flex;
          align-items: center;
        }


      }
    }
  }
}

.bgBox {
  width: 100vw;
  height: 100vh;
  position: fixed;
  z-index: 1;
  background: rgba(0, 0, 0, 0.6);
}

.content {
  position: relative;
  z-index: 99;
  overflow: hidden;
  padding: 20rpx 40rpx;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.left-slot {
  color: #fff;
  display: flex;
  align-items: center;

  image {
    width: 40rpx;
    margin-right: 30rpx;
  }
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* 确保视频填充整个容器，可能会裁剪视频 */
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 0;
}

.outBox {
  background: rgba(0, 0, 0, 0.6);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.textBox{
  p{
  color: #fff;
    margin-top: 20rpx;
	font-weight: 600;
	font-size: 28rpx;
	line-height: 32rpx;
	text-align: center;
	font-style: normal;
	text-align: center;
  }
}
</style>
